<?php
namespace app\admin\controller;
use app\common\validate\AdminValidate;
use app\common\model\Admin as AdminModel;
use utils\PwdUtil;
use utils\RandomStringGenerator;

class Admin extends AdminCommon
{
    public function index(){
        echo  '22';die;
    }


    /**
     * 修改个人密码
     * @desc 修改个人密码
     */
    public function editPwd($id){
        $params = $this->request->param();
        if ($this->request->isAjax() && $this->request->isPost() && isset($params['req_sub'])) {
            //校验器
            $adminValidate = new AdminValidate();
            if (!$adminValidate->scene('editPwd')->check($params)) {
                $this->error($adminValidate->getError());
            }
            $adminModel = new AdminModel();
            $params['salt'] = RandomStringGenerator::generate(10);
            $params['pwd'] = PwdUtil::encode($params['pwd'].$params['salt']);
            if ($adminModel->allowField(true)->save($params, ['id' => $id]) !== false) {
                $this->success('编辑成功', url('admin/admin/editPwd',['id'=>$id]));
            } else {
                $this->error('编辑失败');
            }
        } else {
            $adminModel = new AdminModel();
            $info = $adminModel->get($params['id']);
            $this->assign('info', $info);
            return $this->fetch();
        }
    }
}